package actions.jtest;

import java.awt.*; 
import java.awt.event.KeyEvent; 


/*
*author lange.zyh
*date 2010/1/13
*remark:����������� ��ֵ����� �����С�� ��Χ 50 
*/

public class VolumeController{
        private String cmd = "C:\\Windows\\system32\\sndvol32.exe";
        Robot r;
        
        
        public VolumeController(){
        	try {
				r=new Robot();
			} catch (AWTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            
        }
        
        private void pressKey(Robot r,int keycode){
        	r.keyPress(keycode);
        	r.keyRelease(keycode);
        }
        private void setVolume(int d){
       
       
     r.setAutoDelay(100);
      /*  r.keyPress(KeyEvent.VK_ALT);
	r.keyPress(KeyEvent.VK_TAB);
	r.keyRelease(KeyEvent.VK_TAB);
	r.keyRelease(KeyEvent.VK_ALT);*/
        	
	pressKey(r,KeyEvent.VK_TAB);
	pressKey(r,KeyEvent.VK_TAB);
	
	//pressKey(r,KeyEvent.VK_TAB);
	pressKey(r,KeyEvent.VK_SPACE);
	//r.mouseWheel(100);
	pressKey(r,KeyEvent.VK_ALT);
	pressKey(r,KeyEvent.VK_P);
	pressKey(r,KeyEvent.VK_X);

      
        }
        
        public void setCmd(String args){
        this.cmd = args;
        }
        
        public String getCmd(){
         System.out.println(this.cmd);
         return this.cmd;
        }
        
        public void runCmd(int d){
        try{
        Runtime rt = Runtime.getRuntime();
        Process p = rt.exec(this.cmd);
        p.getInputStream();
        Thread.sleep(1000);
        this.setVolume(d);	
        p.getOutputStream().close();
        p.waitFor();
        p.destroy();
        }catch(Throwable t){
         t.printStackTrace();
        }
        }
        
        public static void main(String[] args){
            VolumeController vc = new VolumeController();
            vc.runCmd(50);
        }
}
